﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Brain
{
    public static class AssemblyUtil
    {
        private static string windowsKey = "b7ceb74a9aff32a4"; // RIGHT
        private static string windowsPhone7Key = "B7CEB74A9AFF32A4"; // RIGHT
        /// <summary>
        /// THE XBOX 360 KEY IS WRONG. Don't have an Xbox 360 to get the Key Token, and I have 
        /// no Idea how to get it without running the Engine
        /// </summary>
        private static string xbox360Key = "56fbde61fac0082a";
        private static string silverlightKey = "56fbde61fac0082a";

        public static string WindowsKeyToken
        {
            get { return windowsKey; }
        }
        public static string Xbox360KeyToken
        {
            get { return xbox360Key; }
        }
        public static string Phone7KeyToken
        {
            get { return windowsPhone7Key; }
        }
        public static string SilverlightKeyToken
        {
            get { return silverlightKey; }
        }

        private static readonly string[] AssemblySplitter = { ", " };

        /// <summary>
        /// Gets the Correct Type string, with the correct Key Token
        /// </summary>
        /// <param name="type"></param>
        /// <param name="platform"></param>
        /// <returns></returns>
        public static string GetCorrectType(Type type, Platform platform)
        {
            string typeName = type.FullName;

            string assName = type.Assembly.FullName;
            string[] split = assName.Split(AssemblySplitter, StringSplitOptions.RemoveEmptyEntries);

            string FinalAssName = typeName + ", " + split[0] + ", " + split[1] + ", " +
                    split[2] + ", " + GetAssemblyPublicKey(platform);

            return FinalAssName;
        }

        public static string GetAssemblyPublicKey(Platform platform)
        {
            string key = "PublicKeyToken=";

            switch (platform)
            {
                case Platform.Windows:
                    key += windowsKey;
                    break;
                case Platform.WindowsPhone:
                    key += windowsPhone7Key;
                    break;
                case Platform.Xbox360:
                    key += xbox360Key;
                    break;
                case Platform.Silverlight:
                    key += silverlightKey;
                    break;
                default:
                    throw new ArgumentException("platform");
            }

            return key;
        }
    }
}
